import { Entity, PrimaryGeneratedColumn, Column, ManyToOne,UpdateDateColumn } from 'typeorm';
import { Order } from './order.entity';

export enum ShippingStatus {
  SHIPPED = 'SHIPPED',
  IN_TRANSIT = 'IN_TRANSIT',
  DELIVERED = 'DELIVERED'
}

@Entity()
export class Shipping {
  @PrimaryGeneratedColumn()
  id: number;

  @ManyToOne(() => Order)
  order: Order;

  @Column()
  courierCompany: string;

  @Column()
  trackingNumber: string;

  @Column({ type: 'timestamp' })
  shippedAt: Date;

  @Column({ type: 'enum', enum: ShippingStatus, default: ShippingStatus.SHIPPED })
  status: ShippingStatus;

  @Column('json')
  apiResponse: Record<string, any>;

  @Column({ type: 'timestamp', default: () => 'CURRENT_TIMESTAMP' })
  @UpdateDateColumn()
  updatedAt: Date;
  @Column({ type: 'json'})
  shippingAddress: {
    name: string;
    phone: string;
    province: string;
    city: string;
    district: string;
    address: string;
  };
}